#include <cstdio>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int n, i, *arr;
    scanf("%d", &n);
    arr = new int[n];
    for (i = 1; i <= n; i++)
    {
        arr[i - 1] = i;
    }
    do
    {
        for (i = 0; i < n; i++)
        {
            printf("%5d", arr[i]);
        }
        printf("\n");
    } while (next_permutation(arr, arr + n));
    
    return 0;
}
